package com.example.myapplication;

import android.content.Context;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class FileSveQQ {
    public static boolean saveUserInfo(Context context,String account,String password,String age){

        FileOutputStream fos=null;
        try{
            fos=context.openFileOutput("cunchu.txt",Context.MODE_PRIVATE);
            fos.write((account+"-"+password).getBytes());
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return true;
        }finally {
            try{
                if (fos!=null)
                    fos.close();
            }catch(IOException e){
                e.printStackTrace();
            }
        }


    }
    public static Map<String,String> getUserInfo(Context context){
        String content="";
        FileInputStream fis = null;
        try{
            fis = context.openFileInput("cunchu.txt");
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            content = new String(buffer);
            HashMap<String,String> userMap = new HashMap<String,String>();
            String[] infos = content.split("-");
            userMap.put("tey1",infos[0]);
            userMap.put("tey2",infos[1]);
            userMap.put("tey3",infos[2]);
            return userMap;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }finally {
            try{
                if (fis!=null)
                    fis.close();
            }catch(IOException e){
                e.printStackTrace();
            }
        }
    }
}
